import ctypes
import os
import pathlib

# 修正DLL路径，使用py_cpp_event目录下的DLL
dll_path = os.path.join(os.path.dirname(__file__), "..", "py_cpp_event", "install", "event_bus.dll")
_SO = pathlib.Path(dll_path)
lib = ctypes.CDLL(str(_SO))

class CEvent(ctypes.Structure):
    _pack_ = 1
    _fields_ = [("id", ctypes.c_int),
                ("payload", ctypes.c_char_p),
                ("payload_size", ctypes.c_size_t)]

# 定义函数
lib.eb_push.argtypes = [ctypes.POINTER(CEvent)]
lib.eb_push.restype = None

def test_simple():
    """简单测试"""
    print("Starting simple test...")
    
    # 创建一个简单的事件
    evt = CEvent()
    evt.id = 0xC0
    payload = b"test_payload"
    evt.payload = payload
    evt.payload_size = len(payload)
    
    print(f"Created event: id={evt.id}, payload={evt.payload}, size={evt.payload_size}")
    
    # 尝试推送事件
    try:
        lib.eb_push(ctypes.byref(evt))
        print("Event pushed successfully")
    except Exception as e:
        print(f"Error pushing event: {e}")
        import traceback
        traceback.print_exc()

if __name__ == "__main__":
    print("Running simple test...")
    test_simple()
    print("Test completed")